package com.open.party.cloud.view.examine

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import cn.android.x.model.data.AppPageData
import cn.android.x.model.data.ResultInfo
import cn.android.x.parent.AppEventBusTitleBaseActivity
import com.open.party.cloud.R
import com.open.party.cloud.model.ArticleEntity
import com.open.party.cloud.view.examine.examineForGanbu.fragment.ExamineForGanBuMoNiCjListFragment
import com.open.party.cloud.view.examine.examineForGanbu.fragment.ExamineForGanBuMoNiSjListFragment
import com.open.party.cloud.view.examine.fragment.ClassExamineHistoryListFragment
import com.open.party.cloud.viewModel.ArticleViewModel
import kotlinx.android.synthetic.main.examine_for_gan_bu_main.*
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class ExamineClassHistoryMainActivity : AppEventBusTitleBaseActivity() {
    private var viewModel: ArticleViewModel? = null

    override fun getLayoutResId(): Int = R.layout.examine_for_gan_bu_main

    @Subscribe(threadMode = ThreadMode.MAIN)
    public fun receiveStudentEventBus(result: ResultInfo<AppPageData<ArticleEntity>>) {
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setViewTitle("成绩查询")
        viewModel = ArticleViewModel()

        initTabView()
    }

    private fun initTabView() {
        val titleList = ArrayList<String>()
//        val typeList = ArrayList<String>()

        titleList.add("成绩查询")

//        typeList.add("GBGZ_ZCFG")
//        typeList.add("HOME_ZGDT")

        initTab(
            titleList,
            getFragments()
        )
    }

    private fun getFragments(): List<Fragment> {
        val fragments: ArrayList<Fragment> = ArrayList()
        fragments.add(ClassExamineHistoryListFragment())
        return fragments
    }

    private fun initTab(titles: ArrayList<String>, fragments: List<Fragment>) {

        val fragmentPagerAdapter = object : FragmentPagerAdapter(supportFragmentManager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
            override fun getCount(): Int {
                return fragments.size
            }

            override fun getItem(arg0: Int): Fragment {
                return fragments[arg0]
            }
        }

        viewPager.offscreenPageLimit = titles.size - 1
        viewPager.adapter = fragmentPagerAdapter
        // pager.addOnPageChangeListener(this);

        scrollTab.visibility = View.GONE
        scrollTab.setTitles(titles, 0) //
//        scrollTab.setNumber(1, "9", View.VISIBLE)//设置数字红点
        scrollTab.setViewPager(viewPager)
        scrollTab.setOnTabListener { index, _ ->
            viewPager.setCurrentItem(index, true)
        }
    }
}